<?php
/**
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 3 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 */
/**
 * Breadcrumb util class
 * @package Util
 * @author Vincze Tamás
 * @version 0.1
 */
namespace Util;
class Breadcrumb {

	/**
	 * Elements for the bradcrumb
	 * @var array nested associative arrays
	 * @example array(array("link" => "/", "name" => Mainpage), array("link" => "/foo", "name" => "Bar"))
	 */
	protected static $_elements = array();

	/**
	 * Add element to the breadcrumb elements list
	 * @param string $name Name of the link
	 * @param string $link URL of the link
	 * @param bool $prefixLinkWithLastElementLink prefix the link of the element with last elment's link, o not
	 * @param array $misc Misc data of the link (class, id, image, anything)
	 */
	public static function add($name, $link, $prefixLinkWithLastElementLink = true, $misc = null) {
		settype($misc, "array");
		if (isset($misc["name"])){
			unset ($misc["name"]);
		}
		if (isset($misc["link"])){
			unset ($misc["link"]);
		}
		if ($prefixLinkWithLastElementLink){
			$link = self::getLastElementLink() . $link;
		}
		$data = array("name" => $name, "link" => $link);
		foreach ($misc as $key => $value) {
			$data[$key] = $value;
		}
		self::$_elements[] = $data;
	}
	
	/**
	 * Return the elements array of SDT objects
	 * @return array array of SDT objects
	 */
	public static function getLastElementLink(){
		if (empty(self::$_elements)){
			return null;
		}
		$last = end(self::$_elements);
		return $last["link"]; 
	}
	
	/**
	 * Return the elements array of SDT objects
	 * @return array array of SDT objects
	 */
	public static function getAll(){
		$return = array();
		foreach (self::$_elements as $element) {
			$return[] = (object) $element;
		}
		return $return; 
	}

	

}

?>
